import { useDetail, useList } from "@/hooks";
import { getUserInfoUrl, urlParams } from "@/command/apiTool";
import { getAction, postAction } from "@/command/netTool";
import * as vant from "vant";
import { useRoute, useRouter } from "vue-router";
import { onMounted, ref } from "vue";
const { showFailToast, showSuccessToast } = vant;
export const useRequest = () => {
  const route = useRoute();
  const router = useRouter();
  // 包装方式
  const [packType] = useDetail(
    "/api/H5/util/getDictType?dictType=pack_type",
    []
  );
  const [myBrandInfo] = useDetail(
    getUserInfoUrl(
      {
        dh: "/api/H5/sell/brand/heavy/myBrandInfo",
        xh: "/api/H5/sell/brand/small/myLeadInfo",
      }
      //不需要传id  与后端沟通过
    ),
    {
      id: "",
      address: "",
      // area: "",
      introduce: "",
      logoUrl: "",
      major: "",
      majorName: "",
      name: "",
      phone: "",
      town: "",
    }
  );
  const confirm = (params: any) => {
    let newParams = {
      ...params,
      id: route.query.id,
      // lat: "29.46",
      // lng: "121.87",
    };
    postAction("/api/H5/sell/brand/heavy/saveInfo", { ...newParams }).then(
      (e) => {
        showSuccessToast("保存成功");
        router.back();
      }
    );
  };

  const [productLevel] = useDetail("/api/H5/util/getProductLevel", []);

  return {
    confirm,
    myBrandInfo,
    packType,
    productLevel,
  };
};
